package com.nc.delivery_project.server.service;

import com.nc.delivery_project.server.dao.AbstractDao;
import com.nc.delivery_project.server.dao.CurrencyDao;
import com.nc.delivery_project.server.domain.Currency;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.List;

/**
 * Created by miroshnik on 1/28/2015.
 */
public class CurrencyService extends BaseService<Currency>{
    
    public CurrencyService() {
        super(new CurrencyDao());
        
    }
    
    public CurrencyService(AbstractDao<Currency> dao, Connection connection, boolean isAutoCloseConnection) {
        super(dao, connection, isAutoCloseConnection);
    }

    public CurrencyService(AbstractDao<Currency> dao) {
        super(dao);
    }

    public CurrencyService(AbstractDao<Currency> dao, Connection connection) {
        super(dao, connection);
    }

    public CurrencyService(AbstractDao<Currency> dao, boolean isAutoCloseConnection) {
        super(dao, isAutoCloseConnection);
    }

    public CurrencyService(Connection connection, boolean isAutoCloseConnection) {
        super(new CurrencyDao(), connection, isAutoCloseConnection);
    }

    @Override
    public List<Currency> read() {
        List<Currency> currencyList = null;
        try {
            Connection conn = getConnection();
            dao.setConnection(conn);
            currencyList = dao.read();
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return currencyList;
    }

    @Override
    public Currency read(int id)  {
        Currency currency = null;
        try {
            dao.setConnection(getConnection());
            currency = dao.read(id);
        } catch (SQLException e) {
            e.printStackTrace();
        }

        return currency;
    }
}
